package com.itheima.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.DateUtils;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时清理上一个月的ordersetting数据
 */
@Component
public class ClearOrderSettingJob {
    @Reference
    private OrderSettingService orderSettingService;
    public void clearOrderSetting(){
        /*
        * 1.获取定时器启动的当前时间
        * 2.把当前时间传给SQL语句作为条件
        * 3.写sql判断orderDate是否小于当前时间，删除小于当前时间的数据
        * */
        try {
            String today = DateUtils.parseDate2String(new Date(), "yyyy-MM-dd");
            orderSettingService.clearOrderSetting(today);
            System.out.println("定时清理上一个月的ordersetting数据");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
